package ar.com.e2solver.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.Polygon;

import ar.com.e2solver.model.Piece;

public class PieceView extends Panel {

	private static final long serialVersionUID = 1L;
	
	private final Polygon polygon1;
	private final Polygon polygon2;
	private final Polygon polygon3;
	private final Polygon polygon4;
	private Piece piece;
	
	public PieceView(Piece piece){
		this.piece = piece;
		setPreferredSize(new Dimension(32,32));
		setSize(new Dimension(32,32));
		setForeground(Color.WHITE);
		setBackground(Color.DARK_GRAY);
		
		int[] arr1a = {0, 0, getSize().width/2};
		int[] arr1b = {0, getSize().height, getSize().height/2};
		polygon1 = new Polygon(arr1a, arr1b, 3);
		
		int[] arr2a = {0, getSize().width/2, getSize().width};
		int[] arr2b = {0, getSize().height/2, 0};
		polygon2 = new Polygon(arr2a, arr2b, 3);
		
		int[] arr3a = {getSize().width/2, getSize().width, getSize().width};
		int[] arr3b = {getSize().height/2, 0, getSize().height};		
		polygon3 = new Polygon(arr3a, arr3b, 3);
		
		int[] arr4a = {0 ,getSize().width/2, getSize().width};
		int[] arr4b = {getSize().height, getSize().height/2, getSize().height};		
		polygon4 = new Polygon(arr4a, arr4b, 3);
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		g.setColor(piece.getLeft());
		g.fillPolygon(polygon1);
		g.setColor(Color.WHITE);
		g.drawPolygon(polygon1);
		
		g.setColor(piece.getTop());
		g.fillPolygon(polygon2);
		g.setColor(Color.WHITE);
		g.drawPolygon(polygon2);
		
		g.setColor(piece.getRight());
		g.fillPolygon(polygon3);
		g.setColor(Color.WHITE);
		g.drawPolygon(polygon3);
		
		g.setColor(piece.getBottom());
		g.fillPolygon(polygon4);
		g.setColor(Color.WHITE);
		g.drawPolygon(polygon4);
	}

}
